<?php
class CommonController extends  BaseController {
	
	public function wxconfig($callback=null, $debug=0)
	{
		$iweixin = new WeixinHelper();
		$access_token = $iweixin->getAccessToken();
		$ticket = $iweixin->getJsapiTicket($access_token);
		$nonceStr  = UtilsHelper::generateRandomString(16);
		$timestamp = time();
		$url = Input::server('HTTP_REFERER');
		if(empty($url)){
			exit('alert("Require Parameter url!")');
		}
		$signature = $iweixin->getSignature($nonceStr, $ticket,$timestamp, $url);
		$appId = Config::get('interface.weixin.APPID');	
		$debug = $debug ? true : false;
		$jsApiList = ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard' ];
		$cfg_arr = compact('appId', 'timestamp', 'nonceStr', 'signature','debug','jsApiList');
                if ($callback) {
		      return Response::make( $callback.'(' . json_encode($cfg_arr).');');
                } else {
                      return Response::make( json_encode($cfg_arr) );
                }
	}
	
	public function addressCode($lat, $lng)
	{
		$result = UtilsHelper::get_client_city_info_by_latlng($lat, $lng);
		Session::put('latlng',"$lat,$lng");
		return Response::make( json_encode($result));	
	}
}